package com.rs.game.player.content;

import java.util.HashMap;
import java.util.Map;

import com.rs.game.Animation;
import com.rs.game.Graphics;
import com.rs.game.item.Item;
import com.rs.game.player.Player;
import com.rs.game.player.Skills;
import com.rs.game.tasks.WorldTask;
import com.rs.game.tasks.WorldTasksManager;
import com.rs.utils.Utils;

/**
 * Add ash scattering
 * 
 * @author Swirl
 * 
 */

public class Scattering {

	public enum Ash {
		IMPIOUS(20264, 56, 4), ACCURSED(20266, 47, 12.5), INFERNAL(20268, 40, 62.5);

		private int id;
		private int gfx;
		private double experience;

		private static Map<Integer, Ash> ashes = new HashMap<Integer, Ash>();

		static {
			for (Ash ash : Ash.values()) {
				ashes.put(ash.getId(), ash);
			}
		}

		public static Ash forId(int id) {
			return ashes.get(id);
		}

		private Ash(int id, int gfx, double experience) {
			this.id = id;
			this.gfx = gfx;
			this.experience = experience;
		}

		public int getId() {
			return id;
		}
		
		public int getGfx() {
			return gfx;
		}

		public double getExperience() {
			return experience;
		}

		public static final Animation SCATTER_ANIMATION = new Animation(445);

		public static void scatter(final Player player, int inventorySlot) {
			final Item item = player.getInventory().getItem(inventorySlot);
			if (item == null || Ash.forId(item.getId()) == null)
				return;
			if (player.getBoneDelay() > Utils.currentTimeMillis())
				return;
			final Ash ash = Ash.forId(item.getId());
			player.addBoneDelay(3000);
			// player.getPackets().sendSound(2738, 0, 1); //TODO: Get correct sound
			player.setNextAnimation(SCATTER_ANIMATION);
			player.setNextGraphics(new Graphics(ash.getGfx()));
			player.isScattering = true;
			player.getPackets().sendGameMessage("You scatter the ashes...");
			WorldTasksManager.schedule(new WorldTask() {
				@Override
				public void run() {
					player.getInventory().deleteItem(item.getId(), 1);
					player.getSkills().addXp(Skills.PRAYER, ash.getExperience());
					stop();
					player.isScattering = false;
				}

			}, 2);
		}
	}
}
